package cn.ecnu.note.mapper;

import cn.ecnu.note.pojo.Note;
import cn.ecnu.note.vo.NoteVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface NoteMapper {

    int insertNote(Note note);

    NoteVo getNoteVoById(@Param("noteId") Integer noteId);

    @Select("SELECT * FROM note WHERE note_id = #{noteId} AND flag = 1")
    Note getNoteById(@Param("noteId") Integer noteId);

    @Update("UPDATE note SET flag = 0 WHERE note_id = #{noteId}")
    int deleteNoteById(@Param("noteId") Integer noteId);

    @Select("SELECT COUNT(*) FROM note WHERE paper_id = #{paperId} AND flag = 1")
    int getNoteCountByPaperId(@Param("paperId") Integer paperId);


    List<NoteVo> getNoteByPaperId(@Param("paperId") Integer paperId, @Param("startNum") int startNum, @Param("pageSize") int pageSize);

    @Select("SELECT COUNT(*) FROM note WHERE user_id = #{userId} AND flag = 1")
    int getNoteCountByUserId(@Param("userId") Integer userId);

    List<NoteVo> getNoteByUserId(@Param("userId") Integer userId, @Param("startNum") int startNum, @Param("pageSize") int pageSize);

    int updateNoteById(Note note);

    NoteVo getNoteByNoteId(Integer noteId);
}
